﻿using LiveCharts;
using LiveCharts.Defaults;
using LiveCharts.Wpf;
using Power.Models;
using Power.View.Report;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;

namespace Power.ViewModel.Report
{
    /// <summary>
    /// 缺陷等级图
    /// </summary>
    public class DefectLevelChartsViewModel : ReportTableBase
    {
        public List<DefectLevelChartData> Data { get; set; }
        private DefectLevelCharts model;
        public DefectLevelChartsViewModel(DefectLevelCharts model)
        {
            this.model = model;
            Data = new List<DefectLevelChartData>() { 
                new DefectLevelChartData(){Level1=1,Level2 =2,Level3=3,Level4=4},
                new DefectLevelChartData(){Level1=1,Level2 =2,Level3=3,Level4=4},
                new DefectLevelChartData(){Level1=1,Level2 =2,Level3=3,Level4=4},
            };

            Init();
        }
        public List<T> CreateEntity<T>(int count)
        {
            var list = new List<T>();

            for (int i = 0; i < count; i++)
            {
                var obj = Activator.CreateInstance(typeof(T));

                var type = obj.GetType();
                var props = type.GetProperties();
                foreach (var item in props)
                {
                    if (item.PropertyType == typeof(int))
                    {
                        item.SetValue(obj, 1);
                    }
                    else if (item.PropertyType == typeof(string))
                    {
                        item.SetValue(obj, "2");
                    }
                }
                list.Add((T)obj);
            }

            return list;
        }
        public void Init()
        {

            var chart1 = this.model.Series1;
            var chart2 = this.model.Series2;
            var chart3 = this.model.Series3;

            //结构性
            var item1 = Data[0];
            var item2 = Data[0];
            var item3 = Data[0];
            chart1.Series = new SeriesCollection
            {
                new PieSeries
                {
                    Title = "1级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item1.Level1)},
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(110,163,255))
                },
                new PieSeries
                {
                    Title = "2级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item1.Level2) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(38,217,115))
                },
                new PieSeries
                {
                    Title = "3级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item1.Level3) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(255,145,71))
                },
                new PieSeries
                {
                    Title = "4级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item1.Level4) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(255,87,87))
                }
            }; ;
            //功能性
            chart2.Series = new SeriesCollection
            {
                new PieSeries
                {
                    Title = "1级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item2.Level1) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(110,163,255))
                },
                new PieSeries
                {
                    Title = "2级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item2.Level2) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(38,217,115))
                },
                new PieSeries
                {
                    Title = "3级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item2.Level3) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(255,145,71))
                },
                new PieSeries
                {
                    Title = "4级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item2.Level4) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(255,87,87))
                }
            };
            chart3.Series = new SeriesCollection
            {
                new PieSeries
                {
                    Title = "1级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item3.Level1) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(110,163,255))
                },
                new PieSeries
                {
                    Title = "2级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item3.Level2) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(38,217,115))
                },
                new PieSeries
                {
                    Title = "3级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item3.Level3) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(255,145,71))
                },
                new PieSeries
                {
                    Title = "4级",
                    Values = new ChartValues<ObservableValue> { new ObservableValue(item3.Level4) },
                    DataLabels = true,
                    Fill = new SolidColorBrush(Color.FromRgb(255,87,87))
                }
            }; ;
        }
    }
}
